package com.springboot.cloud.autoconfigure.aop;

import com.alibaba.fastjson.JSON;
import com.springboot.cloud.core.annotation.SystemLog;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;

/**
 * <p>  </p>
 *
 * @author Bertram
 * @since 10/30/2019 2:07 PM
 */
@Aspect
public class SystemLogAspect {

    @Around(value = "@annotation(com.springboot.cloud.core.annotation.SystemLog)")
    public Object handlerControllerMethod(ProceedingJoinPoint pjp) {
        Object result = null;
        Signature signature = pjp.getSignature();
        MethodSignature methodSignature = (MethodSignature)signature;
        Method targetMethod = methodSignature.getMethod();

        long startTime = System.currentTimeMillis();
        // 需要记录日志存库
        if(targetMethod.isAnnotationPresent(SystemLog.class)) {
            // 获取注解
            SystemLog sysLog = targetMethod.getAnnotation(SystemLog.class);
            String controllerName = pjp.getTarget().getClass().getName();
            String args = JSON.toJSONString(pjp.getArgs());
        }
        try {
            result = pjp.proceed();
        } catch (Throwable ignored) {
        }
        return result;
    }
}
